*******************************************************************************
* master file to execute empirical analysis 
*----------------------------------------------
* Created 15.05.2024
* The Gender Investment Gap over the Life-Cycle
* Annika Bacher, annika.bacher@bi.no
*----------------------------------------------
*******************************************************************************

****************************************
************* set paths ****************
****************************************

// !!!!! NEED TO SET THESE PATHS BEFORE RUNNING THE CODES !!!!!

// FOLDERS IN WHICH RAW DATA FOR RESPECTIVE DATASETS ARE STORED 
global scfrawdata ""
global scerawdata ""
global psidrawdata ""

// FOLDERS IN WHICH WORKED DATASETS FOR RESPECTIVE SOURCE SHOULD BE SAVED
global scfwkddata  ""
global scewkddata  ""
global psidwkddata ""

// FOLDERS IN WHICH DO FILES FOR RESPECTIVE DATASET ARE STORED 
global doscf  ""  // SCF
global dopsid "" // PSID
global dosce  ""  // SCE

// FOLDER FOR CPI DATA
global cpipath "" 

// FOLDERS IN WHICH RESULTS WILL BE STORED (FIGURES AND TABLES)
global resultpath ""

*************************************************************
***** Results from Survey of Consumer Finances (SCF) ********
*************************************************************

// combine individual waves from raw data. 
do "$doscf/1_combine_waves"

// adjust combined data (sample selection, variables definition etc.)
do "$doscf/2_adjust_alldata"

// main anlysis with SCF data (Figures 1,9,10 and Tables 1,9,10)
do "$doscf/3_analysis"

// robustness on housing (Figures 11,12)
do "$doscf/4_housing_robustness"

// robustness on bequests (Table 8)
do "$doscf/5_model_robustness"

*****************************************************************
***** Results from Panel Study of Income Dynamics (PSID) ********
*****************************************************************

// !! NOTE: need to ajust the paths in raw data files to be able to run PSID codes !!

//  merge together the individual-year family files + wealth files
do "$dopsid/1_combine_famwaves"

// takes ind. file (2017 version) and adjusts it to be combined with family files
do "$dopsid/2_combine_famind"

// takes the combined dataset and prepares variables for analysis
do "$dopsid/3_adjust_famwaves"

// produces life cycle profiles from PSID data (Figure 8)
do "$dopsid/4_lcgraphs_moments"

// estimates deterministic income profiles (Figure 2 and Table 11)
// exports residuals for stochastic income estimation in matlab
do "$dopsid/5_estimate_incomeprocess"

// marriage and divorce probabilities (Table 12)
do "$dopsid/6_marital_transition"

// some first stage parameters: sample size, initial conditions, marriage market, equivalence scales (Figure 14)
do "$dopsid/7_parameters_first_stage"

*****************************************************************
***** Results from Survey of Consumer Expectations (SCE) ********
*****************************************************************

// Direct Survey Evidence on Expectations (Figure 7 and Table 6)
do "$dosce/analysis_sce"